package pt.ipl.isel.deetc.leic.pdm.g12.yamba;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class StatusHelper extends SQLiteOpenHelper {
	static final String TAG = "PDMG12";
	static final String DB_NAME = "pdmg12.db";
	static final int DB_VERSION = 1;

	public StatusHelper(Context ctx) {
		super(ctx, DB_NAME, null, DB_VERSION);
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		String columns = StatusToPostContract._ID + " integer primary key autoincrement, "				       
				+ StatusToPostContract.STATUS + " text not null";
		String sql = "CREATE TABLE "+ StatusToPostContract.TABLE + "( "+ columns + " )";
		db.execSQL(sql);
		Log.d(TAG,"sql= "+sql);
		
		columns = StatusContract._ID + " integer primary key, "				       
				+ StatusContract.USER + " text not null, "
				+ StatusContract.DATE_CREATED + " int, "
				+ StatusContract.STATUS + " text not null";
		sql = "CREATE TABLE "+ StatusContract.TABLE + "( "+ columns + " )";
		db.execSQL(sql);
		Log.d(TAG,"sql= "+sql);
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		db.execSQL("DROP TABLE if exists " + StatusToPostContract.TABLE);
		db.execSQL("DROP TABLE if exists " + StatusContract.TABLE); 
		Log.d(TAG, "onUpdated");
		onCreate(db);		
	}
}
